package com.algorithm4;

import java.util.Arrays;

public class BubbleSort {
    public  static void main(String[] args){

        int[] array = {10,9,8,7,6,5,4,3,2,1};
        sort(array);
        System.out.println("排序结果:"+ Arrays.toString(array));
    }
    public static void sort(int[] array){
        for(int i=0;i<array.length-1;i++){
            for(int j=1;j<array.length-i;j++){
                if(array[j-1]>array[j]){
                    swap(array,j,j-1);
                }
            }
            System.out.println("sort "+i+"-->"+ Arrays.toString(array));
        }
    }
    public static void swap(int[] array,int i,int j){
        int temp = array[i];
        array[i] = array[j];
        array[j] = temp;
    }


}
